/***************************************************************************
//* Foxit Software Inc.
//* Copyright(C) 2005-2014, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
//* and trade secrets of Foxit Software Inc.                                                      *
***************************************************************************/
define(function (require, exports, module) {
    var PDFDocView = require('./PDFDocView');
    var LayoutInfo = require('./LayoutInfo');
    /**
     * Mainframe view.
     * @class Mainframe view.
     * @constructor
     * @param {String} mainFrameID  ID of the mainframe div.
     * @param {String} leftPanelID  ID of the navigation panel.
     * @param {WebPDF.IPDFDocument} pdfDoc PDF document object.
     * @param {WebPDF.IPageViewRender} pageViewRender Render object.
 	 * @param {WebPDF.PDFView.LayoutInfo} layoutInfo 	 Layout information.
 	 * @param {WebPDF.ReaderApp} readerApp App object.
     * @return A mainframe view
     * @ignore
     */
    WebPDF.PDFView.CMainFrame = function (mainFrameID, leftPanelID,
                                            pdfDoc, pageViewRender, layoutInfo, readerApp) {
        var   _docView = null,
              _leftPanelID = leftPanelID,
              this.mainFrameID = mainFrameID,
              _readerApp = readerApp;

        _init();
        function _init() {
            _docView = new PDFDocView(pdfDoc, pageViewRender, this.mainFrameID, layoutInfo, _readerApp);
            var jqMainFrame = $("#" + this.mainFrameID);
            _docView.setDocViewWidth(jqMainFrame.width());
            _docView.setDocViewHeight(jqMainFrame.height());
         //   _docView.setDocViewWidth($(window).width());
          //  _docView.setDocViewHeight($(window).height());
            _docView.init();
        }

        /**
         * @description Get the doc view.
         * @return {WebPDF.PDFView.PDFDocView} Doc view object.
         */
        this.getDocView = function () {
            return _docView;
        };
        /**
         * @description Get the ID of the mainframe div.
         * @return {String} ID of the mainframe div.
         */
        this.getMainFrameID = function () {
            return this.mainFrameID;
        };
        /**
         * @description Get the ID of the navigation panel div.
         * @return {String} ID of the navigation panel div.
         */
        this.getLeftPanelID = function () {
            return _leftPanelID;
        };

        this.onResize = function (mainFrameWidth, mainFrameHeight) {
            var jqMainFrame = $("#" + this.mainFrameID);
            if(mainFrameWidth || mainFrameHeight){
                jqMainFrame.width(mainFrameWidth);
                jqMainFrame.height(mainFrameHeight);
            }
            var mainFrameWidth = jqMainFrame.outerWidth();
            var mainFrameHeight = jqMainFrame.outerHeight();
            var jqLeftPanel = $("#" + _leftPanelID);
            var leftPanelHeight = mainFrameHeight;
            var leftPanelWidth = jqLeftPanel.is(":hidden") ? 0 : jqLeftPanel.innerWidth();
            jqLeftPanel.css({ top: 0, height: leftPanelHeight });
            if (_docView != null) {
                var docViewWidth = mainFrameWidth - leftPanelWidth;
                var docViewHeight = mainFrameHeight;
                var docViewOffsetLeft = leftPanelWidth;
                var docViewOffsetTop = 0;
                //check whether the size of doc view has been changed.
                if (docViewWidth===_docView.getDocViewWidth() && docViewHeight===_docView.getDocViewHeight()
                    && docViewOffsetLeft===_docView.getDocViewOffsetLeft() && docViewOffsetTop===_docView.getDocViewOffsetTop()){
                    return;
                }
                _docView.onSize(docViewWidth, docViewHeight, docViewOffsetLeft, docViewOffsetTop);
            }
        };
    };
    return WebPDF.PDFView.CMainFrame;
});